package zhibi.cms.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhibi.cms.domain.Article;
import zhibi.cms.extra.context.Constant;
import zhibi.cms.service.ArticleService;
import zhibi.commons.response.JsonResult;
import zhibi.frame.domain.Page;
import zhibi.frame.mybatis.example.Example;
import zhibi.frame.mybatis.example.ExampleType;
import zhibi.frame.springmvc.base.AbstractController;

@RestController
@RequestMapping(Constant.SYS_PREFIX + "/article")
public class CmsArticleController extends AbstractController {

    @Autowired
    private ArticleService articleService;

    /**
     * 查看栏目的文章列表
     *
     * @param site
     * @param page
     * @return
     */
    @RequestMapping("listBySite")
    public JsonResult<PageInfo> listBySite(String site, Page page) {
        Example example = Example.getInstance()
                .addParam("s.flag", site)
                .addParam("a.status", 1)
                .addOrder("a.sort", ExampleType.OrderType.DESC);
        return JsonResult.success(articleService.selectPoByExample(example, page));
    }

    /**
     * 文章详情
     *
     * @param id
     * @return
     */
    @RequestMapping("findById")
    public JsonResult<Article> findById(String id) {
        return JsonResult.success(articleService.selectByPrimaryKey(id));
    }

}
